#!/usr/bin/env python
#
# @author: Samuel Taylor <samtaylor.uk@gmail.com>
# @package: winecellar
# @license: GNU GPLv3
#
# Copyright (C) 2010  Samuel Taylor <samtaylor.uk@gmail.com>
#----------------------------------------------------------------------
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#-----------------------------------------------------------------------

__author__ = 'Samuel Taylor <samtaylor.uk@gmail.com>'

import urllib
import urlparse

class Download:
    #TODO: Download Cache 
    def __init__(self, url, localUri, updateHook=None):

        self.localUri = localUri
        self.url = url
        self.updateHook = updateHook
        
        self.download()
        
    def download(self):
        split = urlparse.urlsplit(self.url)
        filename = self.localUri + "/" + urllib.unquote(split.path.split("/")[-1])
        urllib.urlretrieve(self.url, filename, self.updateHook)
